package cn.wolfcode.wolf2w.business.controller;

import cn.wolfcode.wolf2w.business.domain.Strategy;
import cn.wolfcode.wolf2w.business.service.DeepSeekService;
import cn.wolfcode.wolf2w.business.service.StrategyService;
import cn.wolfcode.wolf2w.business.dto.ChatRequest;
import cn.wolfcode.wolf2w.business.dto.ChatResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;
import java.util.List;

/**
 * @author : 邓风来
 * @date : 2025/9/30 11:38
 */
@RestController
public class ChatController {
    @Autowired
    private StrategyService strategyService;
    @Autowired
    private DeepSeekService deepSeekService;
    @PostMapping("/chat")
    public ChatResponse chat(@RequestBody ChatRequest request) throws IOException {
        //1.查询私有库(ES)查询私有数据
        List<Strategy> strategies = strategyService.search(request.getQuestion(), 10);

        //2.发送请求到DeepSeek,获取返回结果
        String answer = deepSeekService.askWithStrategies(request.getQuestion(), strategies);
        //3.整合结果并返回
        ChatResponse chatResponse = new ChatResponse(answer, strategies);
        return chatResponse;

    }
}
